class WelcomeController < ApplicationController
  before_filter :login_required
  
  def home
    session[:selected_project_id] = nil
    render :action=>"home", :layout=>"blank_layout"
  end

  def testtab
    render :action=>"testtab", :layout=>false
  end

  def unauto
    render :text=>"Unauthorized", :layout=>"blank_layout"
  end

  def testtree
    render :action=>"testtree", :layout=>"blank_layout"
  end

  def testemail
    render :text=>"tchaiyo@gmail.com.th".index(/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i)
  end

  def test_recordselect
    render :action=>"test_recordselect", :layout=>"blank_layout"
  end

  def test_reg
    require 'statsample'
    a=1000.times.collect {rand}.to_scale
    b=1000.times.collect {rand}.to_scale
    c=1000.times.collect {rand}.to_scale
    ds={'aa'=>a,'bb'=>b,'cc'=>c}.to_dataset
    ds['y']=ds.collect{|row| row['aa']*5+row['bb']*3+row['cc']*2+rand()}
    lr=Statsample::Regression.multiple(ds,'y')
    @t =  lr.coeffs["bb"]
    render :action=>"test_reg"
  end

  def test_chart
    render :action=>"test_chart"
  end

  def match_set_name
    render :action=>"match_set_name"
  end

  def do_match_set_name
    content = params[:csv].read
		s = content
		s.each do |line|
			line2 = line
			line2 = line2.gsub("\r","")
			line2 = line2.gsub("\n","")
			cols = line2.split(',')
      stock = Stock.find(:first, :conditions=>["s_symbol=?", cols[0]], :order=>"id")
      if stock
        if !cols[1].empty?
          stock.s_symbol = cols[1]
          stock.save
        end
      end
    end
    render :text=>"done"
  end
end
